<?php
/****************************************************************************

	COPYRIGHT(C) WWW.MAXSI.DK, MAXSI SOFTWARE, SORTIE 2009
	ALL RIGHTS RESERVED

	Maxsi Distribution ContentServer/ Branch
	Scripts running a Maxsi Distribution Compatible Content Server.	
	
	download.php
	Donloads multiple files from an archive. Obsolete.

****************************************************************************/

	// TODO: DELETE THIS FILE!

	die('This action is obsolete because of security flaws.');

	$file_num = $_POST['File_Num'];
	
	header('Content-Type: application/x-MaxsiEngineFileStream');
	header('Transfer-Encoding: chunked');
	
	if (!isset($_POST['File_Num']))
	{
		die("Content-Type: application/x-MaxsiEngineEmptyFile\r\n\r\n");
	}
	
	
	$counter = 0;
	$CHUNKSIZE = 512*1024;
	$failures = 0;
	
	do
	{
		if (!isset($_POST['File_'.$counter]))
		{
			$error = 'ErrorMsgBox "Server-side error: Post var File_'.$counter.' not recieved. Please ensure you are using a working and updated installer"';
			echo "Content-Type: application/x-MaxsiEngineInstallScript\r\nContent-Lenght: ".strlen($error)."\r\nContent-Name: ".$file_name."\r\n\r\n".$error;	
		}
		else
		{
			$file_name			= stripslashes($_POST['File_'.$counter]);
			$content_archieve	= stripslashes($_GET['content_archieve']);
			if (file_exists($content_archieve.'/'.$file_name))
			{
				$file_size			=	filesize($content_archieve.'/'.$file_name);
				$left				=	$file_size;
				echo "Content-Type: application/x-MaxsiEngineFile\r\nContent-Lenght: ".$file_size."\r\nContent-Name: ".$file_name."\r\n\r\n";
				
				while ($left > 0)
				{
					if ($left > $CHUNKSIZE)
					{
						echo file_get_contents($content_archieve.'/'.$file_name,true,NULL,$file_size-$left,$CHUNKSIZE);
						$left-=$CHUNKSIZE;
					}
					else
					{
						echo file_get_contents($content_archieve.'/'.$file_name,true,NULL,$file_size-$left,$left);
						$left=0;
					}
				}				
			}
			else
			{
				$failures+=1;
				
				if ( $failures < 5)
				{
					// Warning: The file doesn't exist. Report that!
					$error = 'ErrorMsgBox "Server-side error: File '.$file_name.' not found.';
				}
				elseif ( $failures == 5 )
				{
					// Too many errors! Stop posting them
					$error = 'ErrorMsgBox "Server-side error: More than 5 files requested was not found on the server.';
				}
				echo "Content-Type: application/x-MaxsiEngineInstallScript\r\nContent-Lenght: ".strlen($error)."\r\nContent-Name: ".$file_name."\r\n\r\n".$error;
			}
		}
		
		$counter++;
	}
	while ($counter < $file_num)
?>